package com.hjxr.quota.datasource.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hjxr.common.utils.StringUtils;
import com.hjxr.quota.datasource.domain.QuotaDimension;
import com.hjxr.quota.datasource.mapper.QuotaDimensionMapper;
import com.hjxr.quota.util.PageUtil;
import com.hjxr.quota.util.Query;
import com.hjxr.quota.datasource.service.IQuotaDimensionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author sun
 * @since 2020-09-16
 */
@Service
@Transactional(readOnly = true)
public class QuotaDimensionServiceImpl extends ServiceImpl<QuotaDimensionMapper, QuotaDimension> implements IQuotaDimensionService {

    @Override
    public PageUtil selectAllBySearch(Map<String, Object> params) {

        QueryWrapper<QuotaDimension> wrapper = new QueryWrapper<QuotaDimension>().eq("STATUS", 1);
        String key = (String) params.get("key");
        if (StringUtils.isNotBlank(key)) {
            wrapper.like("DIMENSION_NAME", key).or().like("DIMENSION_CODE", key);
        }
        IPage<QuotaDimension> page = this.page(
                new Query<QuotaDimension>().getPage(params),
                wrapper
        );
        return new PageUtil(page);
    }
}
